<template>
  <div class="app-container customer-div">
    <div style="margin-top: 40px">
      <!--搜索-->
      <el-form :inline="true" :model="listQuery" size="mini" label-width="100px">
        <el-form-item label="日期：" >
          <el-date-picker
            v-model="listQuery.FDate"
            type="daterange"
            format="yyyy 年 MM 月 dd 日"
            value-format="yyyy-MM-dd"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item>

        <el-form-item label="单号：" >
            <el-input v-model="listQuery.FBillNo"></el-input>
        </el-form-item>

        <el-form-item label="核销状态：" >
          <el-select v-model="listQuery.hasChecked" filterable placeholder="请选择" clearable>
            <el-option :key="1" label="已核销" :value="1"></el-option>
            <el-option :key="0" label="未核销" :value="0"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="单据类型：" >
          <el-select v-model="listQuery.orderType" filterable placeholder="请选择" clearable>
            <el-option :key="1" label="入库单" value="inWarehouse"></el-option>
            <el-option :key="0" label="出库单" value="outWarehouse"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-button
            @click="handleSearchList()"
            type="primary">
            查询
          </el-button>

        </el-form-item>
      </el-form>
    </div>

    <!--数据列表-->
    <div class="table-container" style="margin-top:0">
      <el-table
        v-loading="listLoading"
        :data="tableData"
        border
        style="width: 100%;">
        <el-table-column  label="日期" min-width="150" align="center">
          <template slot-scope="scope">{{scope.row.FDate}}</template>
        </el-table-column>
        <el-table-column  label="单号" min-width="200" align="center">
          <template slot-scope="scope">
              <el-link style="color:#409EFF;text-decoration: underline" @click="toInfo(scope.row)">{{scope.row.FBillNo}}</el-link>
          </template>
        </el-table-column>
        <el-table-column label="客户/供应商" min-width="200" align="center">
          <template slot-scope="scope">{{scope.row.customerName}}</template>
        </el-table-column>

        <el-table-column  label="核销金额" min-width="150" align="center">
          <template slot-scope="scope">{{scope.row.FCheckAmount}}</template>
        </el-table-column>

      </el-table>
    </div>
    <div class="pagination-container">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        layout="total, sizes,prev, pager, next,jumper"
        :current-page.sync="listQuery.pageNum"
        :page-size="listQuery.pageSize"
        :page-sizes="[10,15,20]"
        :total="count">
      </el-pagination>
    </div>


  </div>
</template>
<script>

import {formatDate} from '@/utils/date';
import store from '@/store'
import { mapGetters } from 'vuex'
import {checkInvoiceList, customGoodsList} from "../../api/partner";
const defaultListQuery={
  pageNum: 1,
  pageSize: 10,
  FDate:[],
  hasChecked:0,
  FBillNo:''
};

export default {
  name: "index",
  data(){
    return {
      listQuery: JSON.parse(JSON.stringify(defaultListQuery)),
      tableData: [],
      count: 0,
      listLoading: false,
      roles:store.getters.roles ? store.getters.roles : [],


    }
  },
  computed: {
    ...mapGetters([
      'name',
      'mobile',
      'userId'
    ]),
  },
  created() {
    let now = new Date();
    let nowMonth = now.getMonth(); //当前月
    let nowYear = now.getFullYear(); //当前年
    //本月的开始时间
    let monthStartDate = new Date(nowYear, nowMonth, 1);
    //本月的结束时间
    let monthEndDate = new Date(nowYear, nowMonth+1, 0,23,59,59);
    let startDate = formatDate(monthStartDate, 'yyyy-MM-dd');
    let endDate = formatDate(monthEndDate, 'yyyy-MM-dd');
    this.listQuery.FDate = [startDate,endDate];
    this.getList();
  },
  filters: {

  },
  methods:{
    toInfo(item){
       if(item.orderType == 'inWarehouse'){
         let routeData = this.$router.resolve({name:'inWarehouseDetail',query:{id:item.FBillNo}});
         window.open(routeData.href);
       }else{
         let routeData = this.$router.resolve({name:'deliverCon',query:{id:item.FBillNo}});
         window.open(routeData.href);
       }
    },

    handleSizeChange(val){
      this.listQuery.pageNum = 1;
      this.listQuery.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val){
      this.listQuery.pageNum = val;
      this.getList();
    },

    handleSearchList(){
      this.listQuery.pageNum = 1;
      this.getList();
    },

    //获取列表
    getList() {
      this.listLoading = true;
      checkInvoiceList(this.listQuery).then(response => {
        this.tableData = response.list;
        this.count = response.count;
        this.listLoading = false;
      }).catch(()=>{
        this.listLoading = false;
      });
    },

  },
}
</script>

<style scoped lang="scss">

.upload-div{
  text-align: center;
  position:relative;
  #upload{

    opacity: 0;
    position: absolute;
    z-index: 1;
    width:154px;
    height:40px
  }
}
</style>
